package com.zretc.kscxmz.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.kscxmz.entity.MailAccount;
import com.zretc.kscxmz.services.MailAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zengyanjun
 * @date 2020-07-21
 */
@Controller
public class MailAccountController {
    @Autowired
    private MailAccountService mailAccountService;

    @RequestMapping(value = "/addMailAccount",method = RequestMethod.POST)
    @ResponseBody
    public String addMailAccount(@RequestBody MailAccount mailAccount){
        int add = mailAccountService.add(mailAccount);
        return add+"";
    }

    @RequestMapping(value = "/updateMailAccount",method = RequestMethod.POST)
    @ResponseBody
    public String updateMailAccount(@RequestBody MailAccount mailAccount){
        int update = mailAccountService.modify(mailAccount);
        return update+"";
    }

    @RequestMapping("/removeMailAccount")
    @ResponseBody
    public String removeMailAccount(@RequestParam("mailAccountId") String mailAccountId){
        int remove = mailAccountService.remove(Integer.parseInt(mailAccountId));
        return remove+"";
    }

    @RequestMapping("/findMailAccount")
    @ResponseBody
    public PageInfo<MailAccount> findMailAccount(@RequestParam("pageNum") String pageNum,
                                  @RequestParam("pageSize") String pageSize,
                                  @RequestParam("mailAccountName") String mailAccountName){
        Map<String,String > map = new HashMap<>();
        map.put("mailAccountName",mailAccountName);
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        PageInfo<MailAccount> mailAccounts = mailAccountService.getMailAccount(map);
        return mailAccounts;
    }
}
